<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>规则集参数信息配置</title>
<link href="../../static/plugin/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
<link href="../../static/plugin/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
<link href="../../static/css/esaas-easyui-edit.css" rel="stylesheet" type="text/css"/>
<script src="../../static/plugin/easyui/jquery.min.js" type="text/javascript"></script>
<script src="../../static/plugin/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../static/plugin/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
<script src="../../ffres/dict/all.js" type="text/javascript"></script>
<a href="" target="_blank" id="commonLink" name="commonLink"></a>
</head>
<script type="text/javascript">
	function loadCollParam(ruleId, dtlId, callback) {
	    $.restfulPostJson("../../api/s/rule/coll/params/dtl/get", {ruleId: ruleId, dtlId: dtlId}, callback);
	}

	function showCollParamView(params) {
		if (!(params && params.length > 0)) {
		    return;
		}
		var columns = [];
        var row = [];
        row.push({field:'ruleId',title:'规则ID', align:'left', resizable: true, width: 100});
        row.push({field:'ruleName',title:'规则名称', align:'left', resizable: true, width: 150});
        row.push({field:'paramConf',title:'参数Key', align:'left', resizable: true, width: 150});
        row.push({field:'paramDesc',title:'参数名称', align:'right', resizable: true, width: 200});
        row.push({field:'paramVal',title:'参数配置值', align:'left',resizable: true, editor:{type:'text'}, width: 400});
        row.push({field:'confDesc',title:'参数描述', align:'left', resizable: true, width: 200});
        columns.push(row);

        $('#paramTb').datagrid({
            singleSelect:true,
            idField:'paramId',
            columns: columns,
            //width:700,
            data: params,
			fitColumns: true,
            onDblClickCell: function(index,field,value){
                if (readonly || field !== 'paramVal') {
                    return;
				}
				var row = $(this).datagrid("getRows")[index];
                if (!row.paramConf) {
                    return;
				}
                $(this).datagrid('beginEdit', index);
                var ed = $(this).datagrid('getEditor', {index:index,field:field});
                $(ed.target).focus();
            }
		});
	}
	var dtlId, ruleId, readonly;
	$(function(){
        ruleId = $.getUrlParam('ruleId');
        dtlId = $.getUrlParam('dtlId');
        readonly = $.getUrlParam('readonly') || "false";
        readonly = readonly === 'true' ? true : false;
        loadCollParam(ruleId, dtlId, function(data) {
            if (data.success) {
                showCollParamView(data.rows);
			} else {

			}
		});
        if (readonly) {
            $('#saveBtn').hide()
        }
	})

	function submitForm() {
		$('#saveBtn').attr("disabled", true);
		var tbData = $('#paramTb').datagrid('getData');
		for (var i=0; i<tbData.total; i++) {
            $('#paramTb').datagrid("endEdit", i);
            $('#paramTb').datagrid("refreshRow", i);
		}
        tbData = $('#paramTb').datagrid('getData');
        $.restfulPostJson("../../api/s/rule/coll/params/dtl/update", tbData.rows, function(data){
            if (data.success) {
                $.messager.alert('提示','保存成功!','info');
                setTimeout(function(){
                    closeForm();
				}, 1000);
            } else {
                $.messager.alert('提示', data.message ,'error');
			}
		});
	}

	function closeForm() {
        window.parent.JLEUtil.closewin();
	}
</script>
<body scroll="no">
<div style="margin-top: 20px; width:95%;margin-left: auto; margin-right: auto;" class="easyui-layout">
	<div class="esaas-info-title">双击参数配置值列启用编辑</div>
	<table class="esaas-info-edit-table" id="paramTb"></table>

	<div style="text-align: center; padding: 15px">
		<a href="javascript:void(0)" class="easyui-linkbutton" id="saveBtn"
		   onclick="submitForm()">&nbsp;保&nbsp;存&nbsp;</a>
		<a href="javascript:void(0)" class="easyui-linkbutton"
			onclick="closeForm()">&nbsp;关&nbsp;闭&nbsp;</a>
	</div>
</div>
</body>
</html>
